home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
accounts
/
acct-1.3
/
acct-1
/
acct-1.3.73
/
kernel_diffs-1.3.70
< prev
next >
Wrap
Text File
|
1996-03-01
|
11KB
|
345 lines
diff -ru --new-file linux-1.3.70/arch/alpha/kernel/signal.c linux/arch/alpha/kernel/signal.c
--- linux-1.3.70/arch/alpha/kernel/signal.c Sat Feb 17 09:19:38 1996
+++ linux/arch/alpha/kernel/signal.c Fri Mar 1 13:16:48 1996
@@ -283,6 +283,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux-1.3.70/arch/i386/kernel/signal.c linux/arch/i386/kernel/signal.c
--- linux-1.3.70/arch/i386/kernel/signal.c Sat Feb 17 08:07:01 1996
+++ linux/arch/i386/kernel/signal.c Fri Mar 1 13:16:48 1996
@@ -215,6 +215,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux-1.3.70/arch/mips/kernel/signal.c linux/arch/mips/kernel/signal.c
--- linux-1.3.70/arch/mips/kernel/signal.c Wed Dec 13 12:39:44 1995
+++ linux/arch/mips/kernel/signal.c Fri Mar 1 13:16:48 1996
@@ -302,6 +302,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux-1.3.70/arch/ppc/kernel/signal.c linux/arch/ppc/kernel/signal.c
--- linux-1.3.70/arch/ppc/kernel/signal.c Sat Dec 30 15:48:22 1995
+++ linux/arch/ppc/kernel/signal.c Fri Mar 1 13:16:49 1996
@@ -166,6 +166,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux-1.3.70/arch/sparc/kernel/signal.c linux/arch/sparc/kernel/signal.c
--- linux-1.3.70/arch/sparc/kernel/signal.c Sun Nov 26 11:50:02 1995
+++ linux/arch/sparc/kernel/signal.c Fri Mar 1 13:16:49 1996
@@ -318,6 +318,7 @@
/* fall through */
default:
current->signal |= _S(signr & 0x7f);
+ current->flags |= PF_SIGNALED;
do_exit(signr);
}
}
diff -ru --new-file linux-1.3.70/fs/binfmt_aout.c linux/fs/binfmt_aout.c
--- linux-1.3.70/fs/binfmt_aout.c Sun Feb 25 11:17:59 1996
+++ linux/fs/binfmt_aout.c Fri Mar 1 13:16:49 1996
@@ -129,6 +129,7 @@
if (!file.f_op->write)
goto close_coredump;
has_dumped = 1;
+ current->flags |= PF_DUMPCORE;
strncpy(dump.u_comm, current->comm, sizeof(current->comm));
dump.u_ar0 = (void *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump)));
dump.signal = signr;
@@ -260,6 +261,7 @@
current->mm->mmap = NULL;
current->suid = current->euid = current->fsuid = bprm->e_uid;
current->sgid = current->egid = current->fsgid = bprm->e_gid;
+ current->flags &= ~PF_FORKNOEXEC;
if (N_MAGIC(ex) == OMAGIC) {
#ifdef __alpha__
do_mmap(NULL, N_TXTADDR(ex) & PAGE_MASK,
diff -ru --new-file linux-1.3.70/fs/binfmt_elf.c linux/fs/binfmt_elf.c
--- linux-1.3.70/fs/binfmt_elf.c Thu Feb 8 06:02:01 1996
+++ linux/fs/binfmt_elf.c Fri Mar 1 13:16:49 1996
@@ -639,6 +639,7 @@
#endif
current->suid = current->euid = current->fsuid = bprm->e_uid;
current->sgid = current->egid = current->fsgid = bprm->e_gid;
+ current->flags &= ~PF_FORKNOEXEC;
bprm->p -= MAX_ARG_PAGES*PAGE_SIZE;
bprm->p = (unsigned long)
create_elf_tables((char *)bprm->p,
@@ -1036,6 +1037,7 @@
if (!file.f_op->write)
goto close_coredump;
has_dumped = 1;
+ current->flags |= PF_DUMPCORE;
DUMP_WRITE(&elf, sizeof(elf));
offset += sizeof(elf); /* Elf header */
diff -ru --new-file linux-1.3.70/include/linux/acct.h linux/include/linux/acct.h
--- linux-1.3.70/include/linux/acct.h Thu Jan 1 02:00:00 1970
+++ linux/include/linux/acct.h Fri Mar 1 13:16:49 1996
@@ -0,0 +1,29 @@
+#ifndef __LINUX_ACCT_H
+#define __LINUX_ACCT_H
+
+#define ACCT_COMM 16
+
+struct acct
+{
+ char ac_comm[ACCT_COMM]; /* Accounting command name */
+ time_t ac_utime; /* Accounting user time */
+ time_t ac_stime; /* Accounting system time */
+ time_t ac_etime; /* Accounting elapsed time */
+ time_t ac_btime; /* Beginning time */
+ uid_t ac_uid; /* Accounting user ID */
+ gid_t ac_gid; /* Accounting group ID */
+ dev_t ac_tty; /* controlling tty */
+ char ac_flag; /* Accounting flag */
+ long ac_minflt; /* Accounting minor pagefaults */
+ long ac_majflt; /* Accounting major pagefaults */
+ long ac_exitcode; /* Accounting process exitcode */
+};
+
+#define AFORK 0001 /* has executed fork, but no exec */
+#define ASU 0002 /* used super-user privileges */
+#define ACORE 0004 /* dumped core */
+#define AXSIG 0010 /* killed by a signal */
+
+#define AHZ 100
+
+#endif
diff -ru --new-file linux-1.3.70/include/linux/kernel.h linux/include/linux/kernel.h
--- linux-1.3.70/include/linux/kernel.h Thu Feb 22 15:51:08 1996
+++ linux/include/linux/kernel.h Fri Mar 1 13:16:50 1996
@@ -58,16 +58,9 @@
__attribute__ ((format (printf, 1, 2)));
/*
- * This is defined as a macro, but at some point this might become a
- * real subroutine that sets a flag if it returns true (to do
- * BSD-style accounting where the process is flagged if it uses root
- * privs). The implication of this is that you should do normal
- * permissions checks first, and check suser() last.
- *
* "suser()" checks against the effective user id, while "fsuser()"
* is used for file permission checking and checks against the fsuid..
*/
-#define suser() (current->euid == 0)
#define fsuser() (current->fsuid == 0)
#endif /* __KERNEL__ */
diff -ru --new-file linux-1.3.70/include/linux/sched.h linux/include/linux/sched.h
--- linux-1.3.70/include/linux/sched.h Fri Mar 1 10:37:14 1996
+++ linux/include/linux/sched.h Fri Mar 1 13:19:50 1996
@@ -259,6 +259,10 @@
/* Not implemented yet, only for 486*/
#define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called. */
#define PF_TRACESYS 0x00000020 /* tracing system calls */
+#define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
+#define PF_SUPERPREV 0x00000100 /* used super-user privileges */
+#define PF_DUMPCORE 0x00000200 /* dumped core */
+#define PF_SIGNALED 0x00000400 /* killed by a signal */
#define PF_STARTING 0x00000100 /* being created */
#define PF_EXITING 0x00000200 /* getting shut down */
@@ -348,6 +352,19 @@
const char *device,
void *dev_id);
extern void free_irq(unsigned int irq, void *dev_id);
+
+/*
+ * This has now become a routine instead of a macro, it sets a flag if
+ * it returns true (to do BSD-style accounting where the process is flagged
+ * if it uses root privs). The implication of this is that you should do
+ * normal permissions checks first, and check suser() last.
+ */
+extern inline int suser(void)
+{
+ if (current->euid == 0)
+ current->flags |= PF_SUPERPREV;
+ return (current->euid == 0);
+}
extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
extern void flush_thread(void);
diff -ru --new-file linux-1.3.70/kernel/exit.c linux/kernel/exit.c
--- linux-1.3.70/kernel/exit.c Sat Feb 17 09:19:43 1996
+++ linux/kernel/exit.c Fri Mar 1 13:16:50 1996
@@ -18,6 +18,7 @@
#include <asm/segment.h>
extern void sem_exit (void);
+extern void acct_process (long exitcode);
extern void kerneld_exit(void);
int getrusage(struct task_struct *, int, struct rusage *);
@@ -509,6 +510,7 @@
intr_count = 0;
}
fake_volatile:
+ acct_process(code);
current->flags |= PF_EXITING;
del_timer(¤t->real_timer);
sem_exit();
diff -ru --new-file linux-1.3.70/kernel/fork.c linux/kernel/fork.c
--- linux-1.3.70/kernel/fork.c Fri Dec 15 12:48:37 1995
+++ linux/kernel/fork.c Fri Mar 1 13:16:50 1996
@@ -226,7 +226,8 @@
p->kernel_stack_page = new_stack;
*(unsigned long *) p->kernel_stack_page = STACK_MAGIC;
p->state = TASK_UNINTERRUPTIBLE;
- p->flags &= ~(PF_PTRACED|PF_TRACESYS);
+ p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV);
+ p->flags |= PF_FORKNOEXEC;
p->pid = get_pid(clone_flags);
p->next_run = NULL;
p->prev_run = NULL;
diff -ru --new-file linux-1.3.70/kernel/sys.c linux/kernel/sys.c
--- linux-1.3.70/kernel/sys.c Fri Mar 1 08:18:12 1996
+++ linux/kernel/sys.c Fri Mar 1 13:16:50 1996
@@ -19,6 +19,10 @@
#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
+#include <linux/fcntl.h>
+#include <linux/acct.h>
+#include <linux/tty.h>
+#include <sys/sysmacros.h>
#include <asm/segment.h>
#include <asm/io.h>
@@ -272,10 +276,113 @@
current->dumpable = 0;
return 0;
}
-
-asmlinkage int sys_acct(void)
-{
- return -ENOSYS;
+
+static char acct_active = 0;
+static struct file acct_file;
+
+int acct_process(long exitcode)
+{
+ struct acct ac;
+ unsigned short fs;
+
+ if (acct_active) {
+ strncpy(ac.ac_comm, current->comm, ACCT_COMM);
+ ac.ac_comm[ACCT_COMM] = '\0';
+ ac.ac_utime = current->utime;
+ ac.ac_stime = current->stime;
+ ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
+ ac.ac_etime = CURRENT_TIME - ac.ac_btime;
+ ac.ac_uid = current->uid;
+ ac.ac_gid = current->gid;
+ ac.ac_tty = (current)->tty == NULL ? -1 :
+ makedev (4, current->tty->device);
+ ac.ac_flag = 0;
+ if (current->flags & PF_FORKNOEXEC)
+ ac.ac_flag |= AFORK;
+ if (current->flags & PF_SUPERPREV)
+ ac.ac_flag |= ASU;
+ if (current->flags & PF_DUMPCORE)
+ ac.ac_flag |= ACORE;
+ if (current->flags & PF_SIGNALED)
+ ac.ac_flag |= AXSIG;
+ ac.ac_minflt = current->min_flt;
+ ac.ac_majflt = current->maj_flt;
+ ac.ac_exitcode = exitcode;
+
+ /* Kernel segment override */
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+
+ acct_file.f_op->write(acct_file.f_inode, &acct_file,
+ (char *)&ac, sizeof(struct acct));
+
+ set_fs(fs);
+ }
+ return 0;
+}
+
+asmlinkage int sys_acct(const char *name)
+{
+ struct inode *inode = (struct inode *)0;
+ char *tmp;
+ int error;
+
+ if (!suser())
+ return -EPERM;
+
+ if (name == (char *)0) {
+ if (acct_active) {
+ if (acct_file.f_op->release)
+ acct_file.f_op->release(acct_file.f_inode, &acct_file);
+
+ if (acct_file.f_inode != (struct inode *) 0)
+ iput(acct_file.f_inode);
+
+ acct_active = 0;
+ }
+ return 0;
+ } else {
+ if (!acct_active) {
+
+ if ((error = getname(name, &tmp)) != 0)
+ return (error);
+
+ error = open_namei(tmp, O_RDWR, 0600, &inode, 0);
+ putname(tmp);
+
+ if (error)
+ return (error);
+
+ if (!S_ISREG(inode->i_mode)) {
+ iput(inode);
+ return -EACCES;
+ }
+
+ if (!inode->i_op || !inode->i_op->default_file_ops ||
+ !inode->i_op->default_file_ops->write) {
+ iput(inode);
+ return -EIO;
+ }
+
+ acct_file.f_mode = 3;
+ acct_file.f_flags = 0;
+ acct_file.f_count = 1;
+ acct_file.f_inode = inode;
+ acct_file.f_pos = inode->i_size;
+ acct_file.f_reada = 0;
+ acct_file.f_op = inode->i_op->default_file_ops;
+
+ if (acct_file.f_op->open)
+ if (acct_file.f_op->open(acct_file.f_inode, &acct_file)) {
+ iput(inode);
+ return -EIO;
+ }
+
+ acct_active = 1;
+ return 0;
+ } else
+ return -EBUSY;
+ }
}
#ifndef __alpha__